<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {
    SelectImage: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImage()),
    SelectDateCycleApplication: async () =>
      Vue.extend(
        await Vue.prototype.$vFN.Components.Base.SelectDateCycleApplication()
      ),
    SelectGoods: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectGoods()),
    SelectDataGoods: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectDataGoods()),
  },
  data() {
    return {
      appWindow: window,
      form: {
        // // 是否开启会员入驻
        // enter_type: 1,
        // // 是否开启会员入驻审核
        // enter_auth: 0,
        // // 是否需要营业执照1需要
        // enter_license: 1,
        // // 是否需要身份证1需要
        // enter_id_card: 1,
        // 新入驻过期类型
        // validity_type: 1,
        // 新入驻过期天数
        // validity_days: 5,
        // 入驻条件1免费2购买指定商品
        // enter_condition: 1,
        // 注册协议
        // agreement_register: "",
        // 入驻协议
        // agreement_enter: "",
        // // 商品列表
        // enter_goods_ids: [],
      },

      goodsIds: [],

      loading: true,
    };
  },
  methods: {
    // 验证 
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs["editForm"].validate((valid) => {
          valid ? resolve(true) : resolve(false)
        });
      });
    },
    async sum() {
      if (!await this.validate()) {
        return
      }
      if(this.form.enter_condition == 2 && this.goodsIds.length <= 0) {
        this.$vFN.Tools.messageError("请添加指定商品")
        return;
      }
      this.loading = true;
      let res = await this.$vFN.Http.post(
        {
          url: "admin/setting/enter",
          data: {
            ...this.form,
            enter_goods_ids: this.goodsIds,
          },
        },
        window
      );
      if (res.success) {
        this.getData();
        this.$vFN.Tools.messageSuccess("操作成功");
      }
    },

    async getData() {
      let res = await this.$vFN.Http.post(
        {
          url: "admin/setting/detail",
        },
        window
      );
      this.form = res.data;
      res.data.goods_list.forEach(item => {
        this.goodsIds.push(item.item.id);
      });
      this.loading = false;
    },

    // 初始化
    async init() {
      this.getData();
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>